#include "UserPrivilege.h"


UserPriReqReader::UserPriReqReader(void)
{
}


UserPriReqReader::~UserPriReqReader(void)
{
}

int UserPriReqReader::read(CommRequest& userLogin)
{
	UserPriReq& userPriReq = static_cast<UserPriReq&>(userLogin);
	TiXmlElement* pChild = m_pRootEle->FirstChildElement("RequestInfo");
	const char* strType = pChild->Attribute("querytype");
	TiXmlElement* pChild2 = pChild->FirstChildElement("GetMtModulesInfo");
	
	userPriReq.uid = pChild2->Attribute("uid");
	userPriReq.token = pChild2->Attribute("token");
	userPriReq.mcflag = pChild2->Attribute("mcflag");

	return 0;
}

UserPriRepWriter::UserPriRepWriter(void)
{
}


UserPriRepWriter::~UserPriRepWriter(void)
{
}
int UserPriRepWriter::doWrite(const CommReply& rep,string& reply)
{
	const UserPriRep& userRep = static_cast<const UserPriRep&>(rep);

	TiXmlElement ResultInfoEle("ResultInfo");
	ResultInfoEle.SetAttribute("resultcode",userRep.status);
	ResultInfoEle.SetAttribute("errormessage","OK");

	m_pRootNode->InsertEndChild(ResultInfoEle);

	TiXmlElement ServiceEle("Service");
	ServiceEle.SetAttribute("business","AAS");
	ServiceEle.SetAttribute("function","getMtModuleList");
	m_pRootNode->InsertEndChild(ServiceEle);

	TiXmlElement ResultDataEle("ResultData");
	ResultDataEle.SetAttribute("querytype","list");

	TiXmlNode* pResultDataNode = m_pRootNode->InsertEndChild(ResultDataEle);

	int size = userRep.vecModule.size();
	for (int i=0;i<size;i++)
	{
		TiXmlElement ModuleEle("Module");
		ModuleEle.SetAttribute("code",userRep.vecModule[i].code);
		ModuleEle.SetAttribute("enable",userRep.vecModule[i].enable);

		TiXmlNode* pAuthNode = pResultDataNode->InsertEndChild(ModuleEle);
	}

	reply << *m_pDoc;

	return 0;
}
